function f() {
    const b = document.getElementsByClassName("tologin");
    let username = document.getElementById("users").value;
    let password = document.getElementById("password").value;
    if (username === "" || password === "") {
        alert("存在任意的数据为空，请重试");
        return;
    }
    if (!VerificationEmail(username)) {
        alert("错误的邮件格式");
        return;
    }if (!VerificationPassword(password)) {
        alert("错误的密码格式，密码应当包含大小写字符以及数字和至少一个特殊字符(!@#$%^&*)，且长度为8~20个字符");
        return;
    }
    let resq;
    const xhr = new XMLHttpRequest();
    xhr.open("post", "./tologin", true);
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.send("username=" + username+ "&password=" + password);
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4 && xhr.status === 200) {
            try {
                resq = JSON.parse(xhr.responseText);
            } catch (err) {
                alert("用户不存在");
                return;
            }
            console.log(resq);

            localStorage.setItem("uid", resq.uid);
            localStorage.setItem("uname", resq.name);
            localStorage.setItem("token", resq.token);

            console.log(localStorage.getItem("uid"));
            console.log(localStorage.getItem("uname"));
            console.log(localStorage.getItem("token"));

            alert("你好," + localStorage.getItem("uname"));
            window.location.href = "/blocks_war_exploded/desktop/home";
        }
    }
}
function VerificationEmail(email) {
    const verificationEmail = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
    return verificationEmail.test(email);
}
function VerificationPassword(password) {
    const verificationPassword = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*]).{8,20}$/;
    return verificationPassword.test(password);
}